<template>
	<view class="inspect">
		<view class="ins_nav">
			<text></text>
			<text class="current_nav">全部</text>
			<text></text>
		</view>
		<scroll-view scroll-y class="ins_list" v-if="healthList.length > 0">
			<view class="ins_item" v-for="(item,index) in healthList" :key='index'>
				<view class="ins_item_fl">
					<view class="fl_child" @click="seePicture(item.img)">
						<image :src="item.img" mode=""></image>
					</view>
				</view>
				<view class="ins_item_fr">
					<text>检查单分析中</text>
					<text>上传时间: {{item.create_time}}</text>
				</view>
			</view>
		</scroll-view>
		<!-- 没有数据 -->
		<view class="ins_nodata" v-else>
			<view class="no_data">
				<image class="data_img" src="https://xcx.shuizhisu.com/public/static/img/nav/nodata.png" mode="">
				</image>
				<text>点击右下角+按钮,就能为您提供检测</text>
				<text>单的专业分析,赶快试一下吧~</text>
			</view>
		</view>
		<view @click="healthUpload">
			<AddInfo />
		</view>
		<!-- 查看大图模式 -->
		<view class="see_picture" v-show="pictureImg" @click="pictureImg = ''">
			<view class="see_picture_box">
				<image style="height: 100%; width: 100%; border-radius: 10rpx;" :src="pictureImg" mode=""></image>
			</view>
		</view>
	</view>
</template>

<script>
	import AddInfo from '../../compon/addinfo.vue'
	export default {
		components: {
			AddInfo
		},
		data() {
			return {
				healthList: [],
				// 预览大图地址
				pictureImg: null
			};
		},
		onShow() {
			this.getHealthList()
		},
		methods: {
			healthUpload() {
				let that = this
				uni.chooseImage({
					count: 1,
					sizeType: ['original', 'compressed'],
					sourceType: ['album', 'camera'],
					success(info) {
						uni.showLoading({
							title: '上传中'
						}) 
						uni.uploadFile({
							url: 'https://xcx.shuizhisu.com/api/health/upload',
							filePath: info.tempFilePaths[0], 
							name: 'file',
							header:{
								"Content-Type": "multipart/form-data", 
							},
							formData:{
								"token": uni.getStorageSync('token')? uni.getStorageSync('token'):''
							},
							success: (res) => { 
								uni.hideLoading()
								that.getHealthList()
							}
						})
						
					}
				})
			},
			// 点击展示大图
			seePicture(url) {
				this.pictureImg = url
				console.log(this.pictureImg)
			},
			// 图片转base64
			// urlTobase64(url) {
			// 	let that = this   
			// 	uni.getFileSystemManager().readFile({
			// 	    filePath: url,
			// 	    encoding: 'base64',  
			// 		success: (r) => {  
			// 			// let base64 = wx.arrayBufferToBase64(r.data); 
			// 			// base64 = 'data:image/jpg;base64,'+base64;
			// 			// console.log(base64)
			// 					that.$api.sendRequest({
			// 						url: 'api/uploadCompress/imgBase64',
			// 						data:{
			// 							images: 'data:image/jpg;base64,' + r.data
			// 						},
			// 						success: res => {
			// 							uni.hideLoading()
			// 						    that.getHealthList()
			// 						}
			// 					}) 
			// 			}
			// 	    }) 
			// },
			// 所有检查单
			getHealthList() {
				this.$api.sendRequest({
					url: '/api/health/lists',
					data: {},
					success: res => {
						if (res.code >= 0) {
							this.healthList = res.data.data
							console.log(this.healthList)
						}
					}
				})
			}
		}
	}
</script>

<style lang="less">
	.inspect {
		.ins_nav {
			display: flex;
			padding: 0 20rpx;
			height: 80rpx;
			line-height: 80rpx;
			text-align: center;
			background-color: #fff;
			border: 2rpx solid #f1f1f1;

			text {
				flex: 1;
			}

			.current_nav {
				color: #4dcd9a;
				border-bottom: 2rpx solid #4dcd9a;
			}
		}

		.ins_list {
			height: calc(100vh - 100rpx);

			.ins_item {
				display: flex;
				padding: 40rpx 20rpx;
				margin-top: 20rpx;
				// height: 120rpx;
				background-color: #fff;

				.ins_item_fl {
					position: relative;
					width: 120rpx;

					.fl_child {
						position: absolute;
						top: 50%;
						left: 50%;
						transform: translate(-50%, -50%);
						width: 90rpx;
						height: 90rpx;
						border-radius: 50%;
						background-color: #bebebe;

						image {
							position: relative;
							left: 50%;
							top: 50%;
							transform: translate(-50%, -50%);
							width: 100%;
							height: 100%;
							border-radius: 50%;
						}
					}
				}

				.ins_item_fr {
					padding-left: 40rpx;
					flex: 1;
					color: #b9b9b9;
					display: flex;
					flex-direction: column;
					justify-content: space-around;
					border-left: 2rpx solid #b9b9b9;

					& text:nth-child(1) {
						font-size: 36rpx;
						color: #3a423f;
					}
				}
			}
		}

		.ins_nodata {
			position: relative;
			height: calc(100vh - 90rpx);
			background-color: #fff;

			.no_data {
				position: absolute;
				top: 40%;
				left: 50%;
				transform: translate(-50%, -50%);
				display: flex;
				flex-direction: column;
				width: 600rpx;
				height: 400rpx;
				color: #8c8c8c;
				text-align: center;

				.data_img {
					margin: 0 auto 30rpx auto;
					width: 180rpx;
					height: 140rpx;
				}
			}
		}

		.see_picture {
			position: fixed;
			top: 0;
			width: 100vw;
			height: 100vh;
			background: rgba(0, 0, 0, .4);

			.see_picture_box {
				width: 85vw;
				height: 50vh;
				position: absolute;
				left: 50%;
				top: 50%;
				transform: translate(-50%, -50%);
			}
		}
	}
</style>
